<?php
include_once "inc_function.php";
session_start();
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Master Product</title>
<script src="../../js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $("#prod_code").focus();
		
     $('input[name=status]').change(function(){	
     	if($('input[name=status]').is(':checked')){
			$(this).val(1);
			$(this).attr('checked', true);
		}else{
			$(this).val(0);
			$(this).attr('checked', false);
		}
     });

		
		$("#save").click(function(){
		txtPC = $("#prod_code").val();
	        txtPN = $("#prod_name").val();
	
			if(txtPC=='')
			{
				alert("Input Product Code... !");
				$("#prod_code").focus;
				return false;
			}
			else if(txtPN=='')
			{
				alert("Input Product Name... !");
				$("#prod_name").focus;
				return false;
			}
		});
    });
</script>

</head>
<body>
<?php
if(isset($_POST['save'])){
$prod_code   = $_POST["prod_code"];
$prod_name   = $_POST["prod_name"];
$ui   = 0;
$ci   = 0;

			if($_POST["status"] == NULL){
				$status   = 0;
			}else{
				$status   = 1;
			}

$sql = 'begin pkg_master.sp_insert_m_product(:s_product_code,:s_product_name,:s_status_id,:s_update_id,:s_create_id); end;';
$stmt_product = oci_parse($con,$sql);
	
	oci_bind_by_name($stmt_product, ':s_product_code',$prod_code);
	oci_bind_by_name($stmt_product, ':s_product_name',$prod_name);
	oci_bind_by_name($stmt_product, ':s_status_id',$status);
	oci_bind_by_name($stmt_product, ':s_update_id',$ui);
	oci_bind_by_name($stmt_product, ':s_create_id',$ci);
	
	oci_execute($stmt_product,OCI_DEFAULT);
	oci_free_statement($stmt_product);
	header('location:product.php');
	
}elseif(isset($_GET['upd'])){
$id = $_GET['upd'];

	$stmt = oci_parse($con,"SELECT a.* FROM m_product a where a.product_id = '$id'");
	oci_execute($stmt);
	$edit = oci_fetch_object($stmt);
	$update = TRUE;
	$z = ($edit->STATUS_ID == 1) ? "CHECKED" : "";
	
}elseif(isset($_POST['cancel'])){
	header('location:product.php');
}
?>

<div id="header">
	<h1 align="center"><?php if ($update === TRUE){ $aksi = "Update";}else{ $aksi = "New";}  echo $aksi; ?> Product</h1>
	<hr noshade="noshade"/>
</div>
	<div id="content">
		<div class="main">
		<form action="<?php if ($update === TRUE){ $aksi = "product.php";}else{ $aksi = $_SERVER['PHP_SELF'];}  echo $aksi; ?>" method="post" name='form_product'>
			<table width="432" border="0" align="center" >
			  <tr>
				<td width="111"><span class="style4">Product Code </span></td>
			<input name="product_id" type="hidden" id="product_id" value="<?php echo isset($edit->PRODUCT_ID) ? $edit->PRODUCT_ID : ''; ?>" >
				<td width="217">
				<input name="prod_code" value="<?php echo isset($edit->PRODUCT_CODE) ? $edit->PRODUCT_CODE : ''; ?>" type="text" id="prod_code" size="30" />
			      <!--	
				  <img src="../../images/search_engine1.png" alt="btnSrc" width="26" height="26" align="absmiddle" onclick=   "window.open('../../lookup/lk_event_code.php','myExample6','width=400,height=400,top=500,left=500,scrollbars=yes')"/>
				  --></td>
				<td width="90" valign="middle">
					<div align="left" class="style2">
					  <input type="checkbox" name="status"
value="<?php echo isset($edit->STATUS_ID) ? $edit->STATUS_ID : ''; ?>"
					   <?php echo $z; ?>/> 
					<span class="style4">Active</span>      </div></td>
			  </tr>
			  <tr>
				<td><span class="style4">Product Name </span></td>
				<td><input name="prod_name" value="<?php echo isset($edit->PRODUCT_NAME) ? $edit->PRODUCT_NAME : ''; ?>" type="text" id="prod_name" size="30" /></td>
				<td>&nbsp;</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td><input 
id="<?php if($update === TRUE){ $aksi = "update";}else{ $aksi = "save";}  echo $aksi; ?>"
name="<?php if($update === TRUE){ $aksi = "update";}else{ $aksi = "save";}  echo $aksi; ?>" type="submit" id="save" value="<?php if($update === TRUE){ $aksi = "Update";}else{ $aksi = "Save";}  echo $aksi; ?>"/>
				<input name="cancel" type="submit" id="cancel" value="Cancel"></td>
				<td>&nbsp;</td>
			  </tr>
			</table>
		</form>
		</div>
	</div>
	

</body>
</html>
